structure Counter :> COUNTER =
struct
  datatype t
    = T of {num : int,
            plist : PropertyList.t}
  
  fun bogus () = T {num = ~1,
                    plist = PropertyList.new ()}
      
  fun plist (T {plist, ...}) = plist
  
  fun compare (T {num = i1, ...}, T {num = i2, ...}) = Int.compare (i1, i2)
  
  val vars : int ref = ref 0
  fun next () =
      let val t = !vars
          val _ = vars := t + 1
      in  T {num = t,
             plist = PropertyList.new ()}
      end
  
  fun init () = vars := 0
  
  fun max () = T {num = 99999999,
                  plist = PropertyList.new ()}
                  
  fun min () = bogus ()
  
  fun equals (k1, k2) = PropertyList.equals (plist k1, plist k2)   
  
  fun println (T {num, ...}) = print (String.concat [Int.toString num, "\n"])
  
  fun toString (T {num, ...}) = String.concat ["C@", Int.toString num]
end
